home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 5
/
Apprentice-Release5.iso
/
Source Code
/
C
/
Applications
/
MacGzip 1.0
/
source
/
Mac
/
GzErrors.c
< prev
next >
Wrap
Text File
|
1995-08-31
|
4KB
|
236 lines
/*
* Errors.c
*
* (c)1990-1995 SPDsoft <MacSPD@ivo.cps.unizar.es>
*
*/
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <errno.h>
#include "FileTypes.h"
#include "Globals.h"
#include "GzErrors.h"
#include "GzPStrings.h"
#define kErrResType 'Errs'
#define kGenericAskID 152
#define kGenericNoteID 153
#define kSysErrAskID 150
#define kSysErrNoteID 151
/*
* Globals
*/
OSErr err;
Str255 error_fmt;
extern int errno;
int DoStdIO( void *foo, const char *fmt, ...);
int DoError( int ErrType, int ErrSever,const char *, ...);
char *GetErrFmt( short ErrType, short ErrID );
static int _DoError( int ErrType, int ErrLevel, char *StrTmp);
/*
* He sintonizado otro canal
* he salido a la calle camuflado
* he dejado de soñar con ovejas eléctricas
* pero no se si estoy preparado...
* para todo lo que vendrá después
*/
char *GetErrFmt( short ErrType, short ErrID )
{
GetIndString( error_fmt, ErrType, ErrID);
p2cstr(error_fmt);
return( (char *) &error_fmt[0] );
}
int DoStdIO( void *foo, const char *fmt, ...)
{
va_list vl;
char StrTmp[256];
va_start(vl,fmt);
vsprintf(StrTmp, fmt, vl);
va_end(vl);
return (_DoError( NO_ERR, WARN_ERR, StrTmp ));
}
int DoError( int ErrType, int ErrLevel, const char *fmt, ...)
{
va_list vl;
char StrTmp[256];
va_start(vl,fmt);
vsprintf(StrTmp, fmt, vl);
va_end(vl);
return (_DoError( ErrType, ErrLevel, StrTmp ));
}
static int _DoError( int ErrType, int ErrLevel, char *StrTmp)
{
Str255 s0, s1, s2, s3;
Handle myHandle;
short alertID;
s0[0]=s1[0]=s2[0]=s3[0]=0x00;
switch(ErrType)
{
case STDC_ERR:
err = (OSErr) errno;
case SYS_ERR:
CStrToStr255( s0, "System Error: ");
CStrToStr255( s1, StrTmp );
if((myHandle=GetResource(kErrResType, (short) err))==nil)
{
NumToString( (long) err, s2 );
}
else
{
PStrCpy(s2, *myHandle );
PStrCpy(s3, (*myHandle)+**myHandle+1 );
}
break;
case PROG_ERR:
CStrToStr255( s0, "Program Error: ");
CStrToStr255( s2, StrTmp );
break;
case INPUT_ERR:
CStrToStr255( s0, "Input error: " );
CStrToStr255( s2, StrTmp );
break;
case NO_ERR:
CStrToStr255( s0, "Warning: " );
CStrToStr255( s2, StrTmp );
break;
default:
CStrToStr255( s0, "What's up?: " );
CStrToStr255( s1, StrTmp );
break;
}
DoNotification();
ParamText(s0, s1, s2, s3);
alertID = ( ( ErrType == SYS_ERR ) || ( ErrType == STDC_ERR ) ) ?
kSysErrNoteID : kGenericNoteID;
switch(ErrLevel)
{
case INFO_ERR:
case WARN_ERR:
StopAlert(alertID, nil);
return(0);
break;
case QUIT_ERR:
case ABORT_ERR:
StopAlert(alertID, nil);
ExitToShell();
break;
case ASK_ERR:
return(
CautionAlert(alertID, nil)
);
break;
case END_ERR:
StopAlert(alertID, nil);
return(1);
break;
default:
return(0);
break;
}
return -1; /* just to make MW compiler happy */
}
void DoNotification( void )
{
static NMRec myNotification;
static Handle myResHand;
static Str255 myText;
EventRecord theEvent;
if ( !gApp.InForeground )
{
myResHand = GetResource('SICN', 128);
HNoPurge(myResHand);
myNotification.qType = nmType;
myNotification.nmMark = 1;
myNotification.nmIcon = myResHand;
myNotification.nmSound = (Handle) -1;
myNotification.nmStr = nil;
myNotification.nmResp = nil;
myNotification.nmRefCon = 0;
NMInstall( (NMRecPtr) &myNotification);
do
{
GetNextEvent(everyEvent, &theEvent);
}
while ( ( theEvent.what != osEvt ) ||
( ((theEvent.message >> 24) & 0x0ff) != suspendResumeMessage ) ||
( (theEvent.message & resumeFlag) == 0 )
);
/*
* Since we are skipping events, probably we will miss some
* update event, but we should finish the process after calling Alert
* so, who cares?
*/
gApp.InForeground = true;
NMRemove( (NMRecPtr) &myNotification);
HPurge(myResHand);
ReleaseResource(myResHand);
}
}